$(document).ready(function () {
    var initFlag = $('#initFlag').val();
    if (initFlag == 2) {
        $('#default-tab-1').removeClass('active in');
        $('#default1').removeClass('active');
        $('#default-tab-2').addClass('active in');
        $('#default2').addClass('active');
        $('#initFlag').val("");
        // $("#toolBar li:eq(2)").addClass("hidden");
        // $("#toolBar li:eq(3)").addClass("hidden");
        // $("#toolBar li:eq(4)").addClass("hidden");
        // $("#toolBar li:eq(5)").addClass("hidden");
        // $("#toolBar li:eq(6)").addClass("hidden");
        // $("#toolBar li:eq(7)").addClass("hidden");
        $("#default3").addClass("hidden");
        $("#default4").addClass("hidden");
        $("#default5").addClass("hidden");
        $("#default6").addClass("hidden");
        $("#default7").addClass("hidden");
        $("#default8").addClass("hidden");
        $("#default9").removeClass("hidden");
    }
    App.init();
    TableManageFixedHeader.init();
    $('.datepicker-default').datepicker({
        language: 'zh-CN',//显示中文
        format: 'yyyy-mm-dd',//显示格式
        autoclose: true,//选中自动关闭
        todayBtn: 'linked'//显示今日按钮
    });

    $("#channels").keyup(function () {
        var name = $("#channels").val();
        if(name!=null&&name!=""){
            $.ajax({
                url:"/channel/findAllChannelName/"+name,
                data:{},
                type:"get",
                success:function (data) {
                    $("#channelsList").html("");
                    $("#channelTid").val("");
                    if(data.success){
                        var channelIds = "";
                        var chHtml = "";
                        for (var i in data.result){
                            console.log("companyRegisterName--------"+data.result[i].companyRegisterName);
                            //var chHtml = "";
                            if(data.result[i].companyRegisterName!=null){
                                chHtml += '<li value='+data.result[i].tid+'>'+data.result[i].companyRegisterName+'</li>';
                            }else{
                                chHtml += '<li value='+data.result[i].tid+'>'+data.result[i].contact.name+'</li>';
                            }
                            channelIds += data.result[i].tid + ",";
                        }
                        channelIds = channelIds.substring(0, channelIds.length - 1);
                        $("#channelsList").html(chHtml);
                        $("#channelsList").parent().addClass("open");
                        $("#channelTid").val(channelIds);
                        $("#channelsList li").click(function () {
                            $("#channels").val($(this).html());
                            $("#channelTid").val($(this).val());
                        })

                    }
                },
                dataType:"json"
            })
        }else{
            $("#channelTid").val("");
            $("#channelsList li").remove();
        }
    })

    $("#orderChannels").keyup(function () {
        var name = $("#orderChannels").val();
        if(name!=null&&name!=""){
            $.ajax({
                url:"/channel/findAllChannelName/"+name,
                data:{},
                type:"get",
                success:function (data) {
                    $("#orderChannelsList").html("");
                    $("#orderChannelId").val("");
                    if(data.success){
                        var channelIds = "";
                        var chHtml = "";
                        for (var i in data.result){
                            console.log("companyRegisterName--------"+data.result[i].companyRegisterName);
                            //var chHtml = "";
                            if(data.result[i].companyRegisterName!=null){
                                chHtml += '<li value='+data.result[i].tid+'>'+data.result[i].companyRegisterName+'</li>';
                            }else{
                                chHtml += '<li value='+data.result[i].tid+'>'+data.result[i].contact.name+'</li>';
                            }
                            channelIds += data.result[i].tid + ",";
                        }
                        channelIds = channelIds.substring(0, channelIds.length - 1);
                        $("#orderChannelsList").html(chHtml);
                        $("#orderChannelsList").parent().addClass("open");
                        $("#orderChannelId").val(channelIds);
                        $("#orderChannelsList li").click(function () {
                            $("#orderChannels").val($(this).html());
                            $("#orderChannelId").val($(this).val());
                        })

                    }
                },
                dataType:"json"
            })
        }else{
            $("#orderChannelId").val("");
            $("#orderChannelsList li").remove();
        }
    })

});

//应收订单分页展示
var table;
$(document).ready(function () {
    table = $("#companytable").DataTable({
        "bAutoWidth": false,
        "order": [],
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [15],//设置一页展示10条记录
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "无匹配结果，请更换筛选条件再试",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        "ajax": {
            "url": "/receivable/queryTableData",
            "dataSrc": "aaData",
            "data": function (params) {
                params.insurer = $('#insurer').val(); //保险公司
                params.channelIds = $('#channelTid').val(); //渠道ID
                params.orderNum = $('#orderNumber').val(); //保单号
                params.plateNumber = $('#plateNumber').val(); //车牌号
                params.paySubject = $('#paymentSubject').val(); //付款主体
                params.issuanceDateStart = $('#issuanceDateStart').val(); //出单日期开始
                params.issuanceDateEnd = $('#issuanceDateEnd').val(); //出单日期结束
                var status = $('#status').val(); //状态
                if(status != 0){
                    params.status = status ;
                }else{
                    params.status = "1,2,3,4,7";
                }
            },
            "error": function (xhr, ts, et) {
                if (ts == "parsererror") {
                    window.location.href = '/logout';
                    return;
                }
            }
        },
        "columns": [
            {"data": null,
                "render": function (data, type, row) {
                    return "<a href='javascript:void(0);' onclick='orderInfoDetail(" + row.ordId + ")' class='btn-link'>" + row.orderNum + "</a>";
                }, "bSortable": false},
            { "data": "paySubject",
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>环宇康泰</span>";else if(data==2)return "<span>青岛盛达</span>";else if(data==3)return "<span>玉环天云</span>";else if(data==4)return "<span>汉龙</span>";
                    return data;
            },"bSortable": false},
            {"data": "insurer", "bSortable": false},
            { "data": "insuranceType",
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>交强险</span>";else if(data==1)return "<span>商业险</span>";
                    return data;
            },"bSortable": false},
            {"data": null,
                "render": function (data, type, row) {
                    return "<div class='text-right'>" + row.realPremium + "</div>";
            },"bSortable": false},
            {"data": null,
                "render": function (data, type, row) {
                    return "<div class='text-right'>" + row.texPremium + "</div>";
            },"bSortable": false},
            {"data": "checkPremium",
                "render": function (data, type, row) {
                    if (data != null && data != '') {
                        if(row.checkPremiumResult==0)return "<div class='text-right' style='color: red'>" + row.checkPremium + "</div>";else return "<div class='text-right'>" + row.checkPremium + "</div>";
                    } else {
                        return "";
                    }
            },"bSortable": false},
            { "data": null ,
                "render": function (data, type, row) {
                    return "<span>" + row.followPoint + "%</span>";
            },"bSortable": false},
            { "data": null,
                "render": function (data, type, row) {
                    return "<span>" + row.replenishPoint + "%</span>";
            },"bSortable": false},
            { "data": "checkFollowPoint",
                "render": function (data, type, row) {
                    if (data != null && data != '') {
                        if (row.checkFollowResult == 0)return "<span style='color: red'>" + row.checkFollowPoint + "%</span>"; else return "<span>" + row.checkFollowPoint + "%</span>";
                    } else {
                        return "";
                    }
            },"bSortable": false},
            { "data": "checkReplenishPoint" ,
                "render": function (data, type, row) {
                    if (data != null && data != '') {
                        if (row.checkReplenishResult == 0)return "<span style='color: red'>" + row.checkReplenishPoint + "%</span>"; else return "<span>" + row.checkReplenishPoint + "%</span>";
                    } else {
                        return "";
                    }
            },"bSortable": false},
            {"data": null,
                "render": function (data, type, row) {
                    return "<div class='text-right'>" + row.followRpoundage + "</div>";
            },"bSortable": false},
            {"data": null,
                "render": function (data, type, row) {
                    return "<div class='text-right'>" + row.replenishRpoundage + "</div>";
            },"bSortable": false},
            { "data": "checkResult" ,
                "render": function (data, type, full, meta) {
                    if(data==2)return "<span>核对不一致</span>";else if(data==1)return "<span>核对一致</span>";else return "<span>--</span>";
                    return data;
            },"bSortable": false},
            { "data": "isTicketOpen" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>未开票</span>";else if(data==1)return "<span>已开票</span>";
                    return data;
            },"bSortable": false},
            { "data": "status" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>待核对</span>";else if(data==2)return "<span>待开票</span>";else if(data==3)return "<span>待收款</span>";else if(data==4)return "<span>待审核</span>";else if(data==7)return "<span>结算审核驳回</span>";
                    return data;
            },"bSortable": false}
        ],
        "columnDefs": [{
            "targets": 16,//是操作按钮目标列
            "data": null,
            "render": function (data, type, row) {
                var html = ""
                if (row.status == 1) {
                    html += "<shiro:hasPermission name='应收保险公司列表-核对'><a href='javascript:void(0);' onclick='orderCheckModal(" + row.tid + ")' class='btn-link'>核对</a></shiro:hasPermission>";
                    html += "&nbsp;&nbsp;&nbsp;&nbsp;<shiro:hasPermission name='应收保险公司列表-退保'><a href='javascript:void(0);' onclick='surrender(" + row.tid + ", " + row.ordId + ")' class='btn-link'>退保</a></shiro:hasPermission>";
                } else if (row.status == 2) {
                    html += "<shiro:hasPermission name='应收保险公司列表-开票'><a href='javascript:void(0);' onclick='orderInvoiceModal(" + row.tid + ")' class='btn-link'>开票</a></shiro:hasPermission>";
                } else if (row.status == 3 || row.status == 7) {
                    html += "<shiro:hasPermission name='应收保险公司列表-收款'><a href='javascript:void(0);' onclick='orderGatheringModal(" + row.tid + ")' class='btn-link'>收款</a></shiro:hasPermission>";
                } else if (row.status == 4) {
                    html += "<shiro:hasPermission name='应收保险公司列表-结算审核'><a href='javascript:void(0);' onclick='settlementAudit(" + row.ordId + ", 1)' class='btn-link'>结算审核</a></shiro:hasPermission>";
                }
                return html;
            }
        }]
    });
});

//批量核对文件上传
function importCheck() {
    var file = document.getElementById("importCheckFile").files[0];
    if (file == null) {
        Ewin.alert("上传文件为空！");
    } else {
        var filesize = Math.floor(file.size / 1024);
        if (filesize > 10000) {
            Ewin.alert("上传文件应不大于10MB！");
            return false;
        }
        var fileName = $("#importCheckFile").val();
        var index = fileName.lastIndexOf(".");
        if (index < 0) {
            Ewin.alert("上传的文件格式不正确，请选择Excel文件！");
        } else {
            var ext = fileName.substring(index + 1, fileName.length);
            if (ext != "xlsx") {
                Ewin.alert("上传的文件格式不正确，请选择Excel文件！");
            } else {
                var formData = new FormData();
                formData.append("myFile", file);
                $.ajax({
                    url: "/receivable/checkBatch",
                    type: "POST",
                    data: formData,
                    //必须false才会自动加上正确的Content-Type
                    contentType: false,
                    //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
                    processData: false,
                    success: function (data) {
                        if (data.success == true) {
                            $('#modalBatchCheck').modal('hide');
                            $("#importCheckFile").val("");
                            var matchingCount = data.result.matchingCount;
                            var noMatchingCount = data.result.noMatchingCount;
                            document.getElementById('matchingCount').innerText = matchingCount;
                            document.getElementById('noMatchingCount').innerText = noMatchingCount;
                            checkData();
                        } else {
                            Ewin.alert(data.msg);
                            return;
                        }
                    },
                    error: function () {
                        Ewin.alert(data.msg);
                    }
                });
            }
        }
        return false;
    }
}

//批量开票文件上传
function importInvoice() {
    var file = document.getElementById("importInvoiceFile").files[0];
    if (file == null) {
        Ewin.alert("上传文件为空！");
    } else {
        var filesize = Math.floor(file.size / 1024);
        if (filesize > 10000) {
            Ewin.alert("上传文件应不大于10MB！");
            return false;
        }
        var fileName = $("#importInvoiceFile").val();
        var index = fileName.lastIndexOf(".");
        if (index < 0) {
            Ewin.alert("上传的文件格式不正确，请选择Excel文件！");
        } else {
            var ext = fileName.substring(index + 1, fileName.length);
            if (ext != "xlsx") {
                Ewin.alert("上传的文件格式不正确，请选择Excel文件！");
            } else {
                var formData = new FormData();
                formData.append("myFile", file);
                $.ajax({
                    url: "/receivable/invoiceBatch",
                    type: "POST",
                    data: formData,
                    //必须false才会自动加上正确的Content-Type
                    contentType: false,
                    //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
                    processData: false,
                    success: function (data) {
                        if (data.success == true) {
                            $('#modalBatchInvoice').modal('hide');
                            $("#importInvoiceFile").val("");
                            var invoiceCount = data.result.invoiceCount;
                            var invoiceAmount = data.result.invoiceAmount;
                            var matchingCount = data.result.matchingCount;
                            var noMatchingCount = data.result.noMatchingCount;
                            document.getElementById('invoiceCount').innerText = invoiceCount;
                            document.getElementById('invoiceAmount').innerText = invoiceAmount;
                            document.getElementById('invoiceMatchingCount').innerText = matchingCount;
                            document.getElementById('invoiceNoMatchingCount').innerText = noMatchingCount;
                            invoiceData();
                        } else {
                            Ewin.alert(data.msg);
                            return;
                        }
                    },
                    error: function () {
                        Ewin.alert(data.msg);
                    }
                });
            }
        }
        return false;
    }
}

//批量收款文件上传
function importGathering() {
    var batchGatheringForm = $('#batchGatheringForm').submit().parsley();
    console.log(batchGatheringForm.isValid());
    if(batchGatheringForm.isValid()) {
        var gatheringFile = document.getElementById("importGatheringFile").files[0];
        var gatheringDate = $('#batchGatheringDate').val();
        if (gatheringFile == null) {
            Ewin.alert("上传文件为空！");
        } else {
            var filesize = Math.floor(gatheringFile.size / 1024);
            if (filesize > 10000) {
                Ewin.alert("上传文件应不大于10MB！");
                return false;
            }
            var fileName = $("#importGatheringFile").val();
            var index = fileName.lastIndexOf(".");
            if (index < 0) {
                Ewin.alert("上传的文件格式不正确，请选择Excel文件！");
            } else {
                var ext = fileName.substring(index + 1, fileName.length);
                if (ext != "xlsx") {
                    Ewin.alert("上传的文件格式不正确，请选择Excel文件！");
                } else {
                    var formData = new FormData();
                    formData.append("myFile", gatheringFile);
                    formData.append("gatheringDate", gatheringDate);
                    $.ajax({
                        url: "/receivable/gatheringBatch",
                        type: "POST",
                        data: formData,
                        //必须false才会自动加上正确的Content-Type
                        contentType: false,
                        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
                        processData: false,
                        success: function (data) {
                            if (data.success == true) {
                                $('#modalBatchGathering').modal('hide');
                                $("#importGatheringFile").val("");
                                var gatheringCount = data.result.gatheringCount;
                                var gatheringAmount = data.result.gatheringAmount;
                                document.getElementById('gatheringCount').innerText = gatheringCount;
                                document.getElementById('gatheringAmount').innerText = gatheringAmount;
                                gatheringData();
                            } else {
                                Ewin.alert(data.msg);
                                return;
                            }
                        },
                        error: function () {
                            Ewin.alert(data.msg);
                        }
                    });
                }
            }
            return false;
        }
    }
}

//批量核对结果分页展示
var checkDataTable;
function checkData() {
    checkDataTable = $("#checkDataTable").DataTable({
        "bAutoWidth": false,
        "order": [],
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [5],//设置一页展示10条记录
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "无匹配结果，请更换筛选条件再试",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        "retrieve": true,
        "ajax": {
            "url": "/receivable/queryCheckData",
            "dataSrc": "aaData",
            "data": function (params) {}
        },
        "columns": [
            { "data": "checkResult" ,
              "render": function (data, type, row) {
                 if(row.checkResult==2)return "<span style='color:red;'><i class='fa fa-2x fa-times-circle-o'></i></span>";else if(row.checkResult==1)return "<span style='color:green;'><i class='fa fa-2x fa-check-circle-o'></i></span>";
                 return data;
            },"bSortable": false},
            {"data": "orderNum", "bSortable": false},
            { "data": "paySubject" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>环宇康泰</span>";else if(data==2)return "<span>青岛盛达</span>";else if(data==3)return "<span>玉环天云</span>";else if(data==4)return "<span>汉龙</span>";
                    return data;
                },"bSortable": false},
            {"data": "insurer", "bSortable": false},
            { "data": "insuranceType" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>交强险</span>";else if(data==1)return "<span>商业险</span>";
                    return data;
                },"bSortable": false},
            {"data": "realPremium", "bSortable": false},
            {"data": "signPreminm", "bSortable": false},
            {"data": "checkSignPreminm", "bSortable": false},
            {"data": "followRatio", "bSortable": false},
            {"data": "replenishRatio", "bSortable": false},
            {"data": "checkFollowRatio", "bSortable": false},
            {"data": "checkReplenishRatio", "bSortable": false},
            {"data": "followPoundage", "bSortable": false},
            {"data": "replenishPoundage", "bSortable": false},
            { "data": "checkResult" ,
                "render": function (data, type, full, meta) {
                    if(data==2)return "<span>不一致</span>";else if(data==1)return "<span>一致</span>";
                    return data;
            },"bSortable": false},
            { "data": "isTicketOpen" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>未开票</span>";else if(data==1)return "<span>已开票</span>";
                    return data;
            },"bSortable": false},
            { "data": "status" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>待核对</span>";else if(data==2)return "<span>待开票</span>";else if(data==3)return "<span>待收款</span>";else if(data==4)return "<span>待审核</span>";
                    return data;
            },"bSortable": false}
        ]
    });
    $('#checkDatatab').modal({backdrop: 'static', keyboard: false});
}

//批量核对确认
function confirmCheck() {
    var formData = new FormData();
    $.ajax({
        url: "/receivable/confirmCheck",
        type: "POST",
        data: formData,
        //必须false才会自动加上正确的Content-Type
        contentType: false,
        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        processData: false,
        success: function (data) {
            if (data.success == true) {
                $('#checkDatatab').modal('hide');
                window.parent.location.reload();
            } else {
                Ewin.alert(data.msg);
                return;
            }
        },
        error: function () {
            Ewin.alert(data.msg);
        }
    });
}

//批量开票结果分页展示
var invoiceDataTable;
function invoiceData() {
    invoiceDataTable = $("#invoiceDataTable").DataTable({
        "bAutoWidth": false,
        "order": [],
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [5],//设置一页展示10条记录
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "无匹配结果，请更换筛选条件再试",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        "retrieve": true,
        "ajax": {
            "url": "/receivable/queryCheckData",
            "dataSrc": "aaData",
            "data": function (params) {}
        },
        "columns": [
            {"data": "orderNum", "bSortable": false},
            { "data": "paySubject" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>环宇康泰</span>";else if(data==2)return "<span>青岛盛达</span>";else if(data==3)return "<span>玉环天云</span>";else if(data==4)return "<span>汉龙</span>";
                    return data;
                },"bSortable": false},
            {"data": "insurer", "bSortable": false},
            { "data": "insuranceType" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>交强险</span>";else if(data==1)return "<span>商业险</span>";
                    return data;
                },"bSortable": false},
            {"data": "realPremium", "bSortable": false},
            {"data": "signPreminm", "bSortable": false},
            {"data": "checkSignPreminm", "bSortable": false},
            {"data": "followRatio", "bSortable": false},
            {"data": "replenishRatio", "bSortable": false},
            {"data": "checkFollowRatio", "bSortable": false},
            {"data": "checkReplenishRatio", "bSortable": false},
            {"data": "followPoundage", "bSortable": false},
            {"data": "replenishPoundage", "bSortable": false},
            { "data": "checkResult" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>未核对</span>";else if(data==1)return "<span>一致</span>";else if(data==2)return "<span>不一致</span>";
                    return data;
            },"bSortable": false},
            { "data": "isTicketOpen" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>未开票</span>";else if(data==1)return "<span>已开票</span>";
                    return data;
            },"bSortable": false},
            { "data": "status" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>待核对</span>";else if(data==2)return "<span>待开票</span>";else if(data==3)return "<span>待收款</span>";else if(data==4)return "<span>待审核</span>";
                    return data;
            },"bSortable": false}
        ]
    });
    $('#invoiceDatatab').modal({backdrop: 'static', keyboard: false});
}

//批量开票确认
function confirmInvoice() {
    var formData = new FormData();
    $.ajax({
        url: "/receivable/confirmInvoice",
        type: "POST",
        data: formData,
        //必须false才会自动加上正确的Content-Type
        contentType: false,
        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        processData: false,
        success: function (data) {
            if (data.success == true) {
                $('#checkDatatab').modal('hide');
                window.parent.location.reload();
            } else {
                Ewin.alert(data.msg);
                return;
            }
        },
        error: function () {
            Ewin.alert(data.msg);
        }
    });
}

//批量收款结果分页展示
var gatheringDataTable;
function gatheringData() {
    gatheringDataTable = $("#gatheringDataTable").DataTable({
        "bAutoWidth": false,
        "order": [],
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [5],//设置一页展示10条记录
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "无匹配结果，请更换筛选条件再试",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "当前第 0 - 0 条　共计 0 条",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        "retrieve": true,
        "ajax": {
            "url": "/receivable/queryCheckData",
            "dataSrc": "aaData",
            "data": function (params) {}
        },
        "columns": [
            {"data": "orderNum", "bSortable": false},
            { "data": "paySubject" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>环宇康泰</span>";else if(data==2)return "<span>青岛盛达</span>";else if(data==3)return "<span>玉环天云</span>";else if(data==4)return "<span>汉龙</span>";
                    return data;
                },"bSortable": false},
            {"data": "insurer", "bSortable": false},
            { "data": "insuranceType" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>交强险</span>";else if(data==1)return "<span>商业险</span>";
                    return data;
                },"bSortable": false},
            {"data": "realPremium", "bSortable": false},
            //{"data": "realPremium", "bSortable": false},
            {"data": "signPreminm", "bSortable": false},
            {"data": "checkSignPreminm", "bSortable": false},
            {"data": "followRatio", "bSortable": false},
            {"data": "replenishRatio", "bSortable": false},
            {"data": "checkFollowRatio", "bSortable": false},
            {"data": "checkReplenishRatio", "bSortable": false},
            {"data": "followPoundage", "bSortable": false},
            {"data": "replenishPoundage", "bSortable": false},
            { "data": "checkResult" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>未核对</span>";else if(data==1)return "<span>一致</span>";else if(data==2)return "<span>不一致</span>";
                    return data;
            },"bSortable": false},
            { "data": "isTicketOpen" ,
                "render": function (data, type, full, meta) {
                    if(data==0)return "<span>未开票</span>";else if(data==1)return "<span>已开票</span>";
                    return data;
            },"bSortable": false},
            { "data": "status" ,
                "render": function (data, type, full, meta) {
                    if(data==1)return "<span>待核对</span>";else if(data==2)return "<span>待开票</span>";else if(data==3)return "<span>待收款</span>";else if(data==4)return "<span>待审核</span>";
                    return data;
            },"bSortable": false}
        ]
    });
    $('#gatheringDatatab').modal({backdrop: 'static', keyboard: false});
}

//批量收款确认
function confirmGathering() {
    var formData = new FormData();
    $.ajax({
        url: "/receivable/confirmGathering",
        type: "POST",
        data: formData,
        //必须false才会自动加上正确的Content-Type
        contentType: false,
        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        processData: false,
        success: function (data) {
            if (data.success == true) {
                $('#gatheringDatatab').modal('hide');
                window.parent.location.reload();
            } else {
                Ewin.alert(data.msg);
                return;
            }
        },
        error: function () {
            Ewin.alert(data.msg);
        }
    });
}

//下载查询的应收订单数据
function downloadOrders(reportType) {
    Ewin.confirm({message: "确认下载当前列表信息"}).on(function (e) {
        if (!e) {
            return false;
        }
        if (reportType == 1) { //保险公司
            var insurer = $('#insurer').val(); //保险公司
            var channel = $('#channelTid').val(); //渠道
            var orderNum = $('#orderNumber').val(); //保单号
            var plateNumber = $('#plateNumber').val(); //车牌号
            var paySubject = $('#paymentSubject').val(); //付款主体
            var status = $('#status').val(); //状态
            var issuanceDateStart = $('#issuanceDateStart').val(); //出单日期开始
            var issuanceDateEnd = $('#issuanceDateEnd').val(); //出单日期结束
            if(status == 0){
                status = "1,2,3,4,7";
            }
            window.location.href = "/receivable/download?insurer=" + insurer + "&channelIds=" + channel + "&orderNum=" + orderNum
                + "&plateNumber=" + plateNumber + "&paySubject=" + paySubject + "&issuanceDateStart=" + issuanceDateStart
                + "&issuanceDateEnd=" + issuanceDateEnd + "&status=" + status;
        } else if (reportType == 2) { //渠道
            var insurer = $('#channelInsurer').val(); //保险公司
            var channel = $('#orderChannelId').val(); //渠道
            var orderNum = $('#channelOrderNumber').val(); //保单号
            var plateNumber = $('#channelPlateNumber').val(); //车牌号
            var status = $('#channelStatus').val(); //状态
            var accountMaturityDateStart = $('#accountMaturityDateStart').val(); //出单日期开始
            var accountMaturityDateEnd = $('#accountMaturityDateEnd').val(); //出单日期结束
            if(status == 0){
                status = "3,4,7,8";
            }
            window.location.href = "/receivable/downloadChannel?insurer=" + insurer + "&channelIds=" + channel + "&orderNum=" + orderNum
                + "&plateNumber=" + plateNumber + "&accountMaturityDateStart=" + accountMaturityDateStart
                + "&accountMaturityDateEnd=" + accountMaturityDateEnd + "&status=" + status;
        }
    });
}

//初始化单条订单核对弹出框
function orderCheckModal(id) {
    $('#checkOrderForm').parsley().reset();
    $('#checkTid').val(id);
    $("input:radio[name='checkResultRadio'][value='1']").attr('checked','true');
    $('#checkTexPremium').addClass('hidden');
    $('#checkFollowPoint').addClass('hidden');
    $('#checkReplenishPoint').addClass('hidden');
    $('#inputCheckTexPremium').val('');
    $('#inputCheckFollowPoint').val('');
    $('#inputCheckReplenishPoint').val('');
    $('#inputRemark').val('');
    $('#inputCheckTexPremium').removeAttr('data-parsley-required', true);
    $('#inputCheckTexPremium').removeAttr('data-parsley-required-message', "请输入核对税后保费");
    $('#inputCheckTexPremium').removeAttr('data-parsley-money', true);
    $('#inputCheckTexPremium').removeAttr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
    $('#inputCheckFollowPoint').removeAttr('data-parsley-required', true);
    $('#inputCheckFollowPoint').removeAttr('data-parsley-required-message', "请输入核对跟单点位");
    $('#inputCheckFollowPoint').removeAttr('data-parsley-money', true);
    $('#inputCheckFollowPoint').removeAttr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
    $('#inputCheckReplenishPoint').removeAttr('data-parsley-required', true);
    $('#inputCheckReplenishPoint').removeAttr('data-parsley-required-message', "请输入核对补点点位");
    $('#inputCheckReplenishPoint').removeAttr('data-parsley-money', true);
    $('#inputCheckReplenishPoint').removeAttr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
    $('#inputRemark').removeAttr('data-parsley-required', true);
    $('#inputRemark').removeAttr('data-parsley-required-message', "请输入100字以内的备注");
    $('#modalCheck').modal({backdrop: 'static', keyboard: false});
}

//单条数据核对单选数据初始化
$(document).ready(function() {
    $('input[type=radio][name=checkResultRadio]').change(function() {
        if (this.value == '2') {
            $('#checkTexPremium').removeClass('hidden');
            $('#checkFollowPoint').removeClass('hidden');
            $('#checkReplenishPoint').removeClass('hidden');
            $('#inputCheckTexPremium').attr('data-parsley-required', true);
            $('#inputCheckTexPremium').attr('data-parsley-required-message', "请输入核对税后保费");
            $('#inputCheckTexPremium').attr('data-parsley-money', true);
            $('#inputCheckTexPremium').attr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
            $('#inputCheckFollowPoint').attr('data-parsley-required', true);
            $('#inputCheckFollowPoint').attr('data-parsley-required-message', "请输入核对跟单点位");
            $('#inputCheckFollowPoint').attr('data-parsley-money', true);
            $('#inputCheckFollowPoint').attr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
            $('#inputCheckReplenishPoint').attr('data-parsley-required', true);
            $('#inputCheckReplenishPoint').attr('data-parsley-required-message', "请输入核对补点点位");
            $('#inputCheckReplenishPoint').attr('data-parsley-money', true);
            $('#inputCheckReplenishPoint').attr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
            $('#inputRemark').attr('data-parsley-required', true);
            $('#inputRemark').attr('data-parsley-required-message', "请输入100字以内的备注");
        } else if (this.value == '1') {
            $('#checkTexPremium').addClass('hidden');
            $('#checkFollowPoint').addClass('hidden');
            $('#checkReplenishPoint').addClass('hidden');
            $('#inputCheckTexPremium').val('');
            $('#inputCheckFollowPoint').val('');
            $('#inputCheckReplenishPoint').val('');
            $('#inputCheckTexPremium').removeAttr('data-parsley-required', true);
            $('#inputCheckTexPremium').removeAttr('data-parsley-required-message', "请输入核对税后保费");
            $('#inputCheckTexPremium').removeAttr('data-parsley-money', true);
            $('#inputCheckTexPremium').removeAttr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
            $('#inputCheckFollowPoint').removeAttr('data-parsley-required', true);
            $('#inputCheckFollowPoint').removeAttr('data-parsley-required-message', "请输入核对跟单点位");
            $('#inputCheckFollowPoint').removeAttr('data-parsley-money', true);
            $('#inputCheckFollowPoint').removeAttr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
            $('#inputCheckReplenishPoint').removeAttr('data-parsley-required', true);
            $('#inputCheckReplenishPoint').removeAttr('data-parsley-required-message', "请输入核对补点点位");
            $('#inputCheckReplenishPoint').removeAttr('data-parsley-money', true);
            $('#inputCheckReplenishPoint').removeAttr('data-parsley-money-message', "请输入9位以内的整数或小数且小数点后只有两位");
            $('#inputRemark').removeAttr('data-parsley-required', true);
            $('#inputRemark').removeAttr('data-parsley-required-message', "请输入100字以内的备注");
        }
    });
});

//取消弹出框
function cancelModal(modalId, msg) {
    Ewin.confirm({message: msg}).on(function (e) {
        if (!e) {
            return false;
        }
        $('#' + modalId).modal('hide');
        //window.parent.location.reload();
    });
}

//单条数据核对
function checkOrder() {
    var checkOrderForm = $('#checkOrderForm').submit().parsley();
    console.log(checkOrderForm.isValid());
    if(checkOrderForm.isValid()) {
        var formData = new FormData();
        var tid = $('#checkTid').val();
        var radioValue = $(":radio:checked").val();
        var texPremium = $("#inputCheckTexPremium").val();
        var followPoint = $("#inputCheckFollowPoint").val();
        var replenishPoint = $("#inputCheckReplenishPoint").val();
        var remark = $("#inputRemark").val();
        formData.append("tid", tid);
        formData.append("checkResult", radioValue);
        formData.append("texPremium", texPremium);
        formData.append("followPoint", followPoint);
        formData.append("replenishPoint", replenishPoint);
        formData.append("remark", remark);
        $.ajax({
            url: "/receivable/orderCheck",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                if (data.success == true) {
                    $('#modalCheck').modal('hide');
                    window.parent.location.reload();
                } else {
                    Ewin.alert(data.msg);
                    return;
                }
            },
            error: function () {
                Ewin.alert(data.msg);
            }
        });
    }
}

//初始化单条订单开票弹出框
function orderInvoiceModal(id) {
    $('#invoiceForm').parsley().reset();
    $('#invoiceTid').val(id);
    $('#inputInvoiceDate').val(new Date().Format("yyyy-MM-dd"));
    $('#inputInvoiceRemark').val("");
    $('#modalInvoice').modal({backdrop: 'static', keyboard: false});
}

//单条订单开票
function orderInvoice() {
    var invoiceForm = $('#invoiceForm').submit().parsley();
    console.log(invoiceForm.isValid());
    if(invoiceForm.isValid()) {
        var formData = new FormData();
        var tid = $('#invoiceTid').val();
        var remark = $("#inputInvoiceRemark").val();
        var invoiceDate = $("#inputInvoiceDate").val();
        formData.append("tid", tid);
        formData.append("invoiceDate", invoiceDate);
        formData.append("remark", remark);
        $.ajax({
            url: "/receivable/orderInvoice",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                if (data.success == true) {
                    $('#modalInvoice').modal('hide');
                    window.parent.location.reload();
                } else {
                    Ewin.alert(data.msg);
                    return;
                }
            },
            error: function () {
                Ewin.alert(data.msg);
            }
        });
    }
}

//初始化单条订单收款弹出框
function orderGatheringModal(id) {
    var formData = new FormData();
    formData.append("tid", id);
    $.ajax({
        url: "/receivable/getGatheringData",
        type: "POST",
        data: formData,
        //必须false才会自动加上正确的Content-Type
        contentType: false,
        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        processData: false,
        success: function (data) {
            if (data.success == true) {
                $('#gatheringForm').parsley().reset();
                var mustPremiumAmt = data.result.mustPremiumAmt;
                var followRpoundage = data.result.followRpoundage;
                var replenishRpoundage = data.result.replenishRpoundage;
                $('#inputRealPremiumAmt').val(mustPremiumAmt);
                $('#inputFollowRpoundage').val(followRpoundage);
                $('#inputReplenishRpoundage').val(replenishRpoundage);
                $('#gatheringTid').val(id);
                $('#inputGatheringDate').val(new Date().Format("yyyy-MM-dd"));
                $('#inputGatheringRemark').val("");
                $('#modalGathering').modal({backdrop: 'static', keyboard: false});
            } else {
                Ewin.alert(data.msg);
                return;
            }
        },
        error: function () {
            Ewin.alert(data.msg);
        }
    });
}

//单条订单收款
function orderGathering() {
    var gatheringForm = $('#gatheringForm').submit().parsley();
    console.log(gatheringForm.isValid());
    if(gatheringForm.isValid()) {
        var formData = new FormData();
        var tid = $('#gatheringTid').val();
        var realPremiumAmt = $('#inputRealPremiumAmt').val();
        var followRpoundage = $('#inputFollowRpoundage').val();
        var replenishRpoundage = $('#inputReplenishRpoundage').val();
        var gatheringDate = $("#inputGatheringDate").val();
        var remark = $("#inputGatheringRemark").val();
        formData.append("tid", tid);
        formData.append("realPremiumAmt", realPremiumAmt);
        formData.append("followRpoundage", followRpoundage);
        formData.append("replenishRpoundage", replenishRpoundage);
        formData.append("gatheringDate", gatheringDate);
        formData.append("remark", remark);
        $.ajax({
            url: "/receivable/orderGathering",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                if (data.success == true) {
                    $('#modalGathering').modal('hide');
                    window.parent.location.reload();
                } else {
                    Ewin.alert(data.msg);
                    return;
                }
            },
            error: function () {
                Ewin.alert(data.msg);
            }
        });
    }
}

//结算审核页初始化
function settlementAudit(ordId, turnType) {
    //window.location.href = "/receivable/toSettlementAudit?ordId=" + ordId + "&turnType=" + turnType;
    // $("#toolBar li:eq(0)").removeClass("active");
    // $("#toolBar li:eq(1)").removeClass("active");
    // $("#toolBar li:eq(2)").removeClass("hidden");
    // $("#toolBar li:eq(2)").addClass("active");
    // $("#toolBar li:eq(4)").addClass("hidden");
    // $("#toolBar li:eq(5)").addClass("hidden");
    // $("#toolBar li:eq(6)").addClass("hidden");
    // $("#toolBar li:eq(7)").addClass("hidden");
    $("#auditOpinion").val("");

    $("#default1").removeClass("active");
    $("#default2").removeClass("active");
    $("#default3").removeClass("hidden");
    $("#default3").addClass("active");
    $("#default5").addClass("hidden");
    $("#default6").addClass("hidden");
    $("#default7").addClass("hidden");
    $("#default8").addClass("hidden");
    $("#default9").addClass("hidden");

    $("#sTabul li:eq(0)").addClass("active");
    $("#sTabul li:eq(1)").removeClass("active");
    $("#sTabul li:eq(2)").removeClass("active");
    $("#sTab1").addClass("active in");
    $("#sTab2").removeClass("active in");
    $("#sTab3").removeClass("active in");

    $('#default-tab-1').removeClass('active in');
    $('#default-tab-2').removeClass('active in');
    $('#default-tab-3').addClass('active in');

    var formData = new FormData();
    formData.append("ordId", ordId);
    formData.append("turnType", turnType);
    $.ajax({
        url: "/receivable/toSettlementAudit",
        type: "POST",
        data: formData,
        //必须false才会自动加上正确的Content-Type
        contentType: false,
        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        processData: false,
        success: function (data) {
            if (data.success == true) {
                if (turnType == 1) {
                    $('#capitalTid').val(data.result.companyRecord.tid);
                } else if (turnType == 2) {
                    $('#capitalTid').val(data.result.channelRecord.tid);
                }
                $('#turnType').val(turnType);
                //填充结算审核页保单信息数据
                initOrderInfo(data.result.orderInfo, data.result.companyRecord, data.result.channelRecord);
                //填充结算审核页应付信息数据
                initPayInfo(data.result.companyRecord, data.result.channelRecord);
                //审核页面应收信息初始化
                initReceivableInfo(data.result.orderInfo, data.result.companyRecord, data.result.channelRecord);
                //审核页面订单操作记录初始化
                initBusinessLog(data.result.optionList);
            } else {
                Ewin.alert(data.msg);
                return;
            }
        },
        error: function () {
            Ewin.alert(data.msg);
        }
    });
}

//订单详情页
function orderInfoDetail(ordId) {
    //window.location.href = "/receivable/orderInfoDetail?ordId=" + ordId;

    // $("#toolBar li:eq(0)").removeClass("active in");
    // $("#toolBar li:eq(1)").removeClass("active in");
    // $("#toolBar li:eq(3)").removeClass("hidden");
    // $("#toolBar li:eq(3)").addClass("active in");
    // $("#toolBar li:eq(4)").addClass("hidden");
    // $("#toolBar li:eq(5)").addClass("hidden");
    // $("#toolBar li:eq(6)").addClass("hidden");
    // $("#toolBar li:eq(7)").addClass("hidden");

    $("#default1").removeClass("active in");
    $("#default2").removeClass("active in");
    $("#default4").removeClass("hidden");
    $("#default4").addClass("active in");
    $("#default5").addClass("hidden");
    $("#default6").addClass("hidden");
    $("#default7").addClass("hidden");
    $("#default8").addClass("hidden");
    $("#default9").addClass("hidden");

    $('#default-tab-1').removeClass('active');
    $('#default-tab-2').removeClass('active');
    $('#default-tab-4').addClass('active in');

    $("#orderDetail").attr("src", "/ins/order/orderInfoDetail?tid=" + ordId);
}

//结算审核通过
function adopt() {
    var id = $('#capitalTid').val();
    var turnType = $('#turnType').val();
    var auditForm = $('#auditForm').submit().parsley();
    console.log(auditForm.isValid());
    if(auditForm.isValid()) {
        var formData = new FormData();
        var auditOpinion = $('#auditOpinion').val();
        formData.append("tid", id);
        formData.append("auditOpinion", auditOpinion);
        formData.append("auditType", "adopt");
        $.ajax({
            url: "/receivable/settlementAudit",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                window.location.href = "/receivable/tolist?initFlag=" + turnType;
            },
            error: function () {
                Ewin.alert(data.msg);
            }
        });
    }
}

//结算审核驳回
function reject() {
    var id = $('#capitalTid').val();
    var turnType = $('#turnType').val();
    var auditForm = $('#auditForm').submit().parsley();
    console.log(auditForm.isValid());
    if(auditForm.isValid()) {
        var formData = new FormData();
        var auditOpinion = $('#auditOpinion').val();
        formData.append("tid", id);
        formData.append("auditOpinion", auditOpinion);
        formData.append("auditType", "reject");
        $.ajax({
            url: "/receivable/settlementAudit",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                window.location.href = "/receivable/tolist?initFlag=" + turnType;
            },
            error: function () {
                Ewin.alert(data.msg);
            }
        });
    }
}

//渠道应收结算初始化弹出框
function orderSettlementModal(id, channelId) {
    var formData = new FormData();
    formData.append("tid", id);
    $.ajax({
        url: "/receivable/getSettlementData",
        type: "POST",
        data: formData,
        //必须false才会自动加上正确的Content-Type
        contentType: false,
        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        processData: false,
        success: function (data) {
            if (data.success == true) {
                $('#settlementForm').parsley().reset();
                var realPremium = data.result.realPremium;
                $('#inputRealPremium').val(realPremium);
                $('#settlementTid').val(id);
                $('#channelId').val(channelId);
                $('#inputSettlementDate').val(new Date().Format("yyyy-MM-dd"));
                $('#inputCapitalSourcr').val("");
                $('#inputSettlementRemark').val("");
                $('#modalSettlement').modal({backdrop: 'static', keyboard: false});
            } else {
                Ewin.alert(data.msg);
                return;
            }
        },
        error: function () {
            Ewin.alert(data.msg);
        }
    });
}

//渠道应收结算
function orderSettlement() {
    var settlementForm = $('#settlementForm').submit().parsley();
    console.log(settlementForm.isValid());
    if(settlementForm.isValid()) {
        var formData = new FormData();
        var tid = $('#settlementTid').val();
        var channelId = $('#channelId').val();
        var realPremium = $('#inputRealPremium').val();
        var settlementDate = $("#inputSettlementDate").val();
        var capitalSourcr = $("#inputCapitalSourcr").val();
        var remark = $("#inputSettlementRemark").val();
        formData.append("tid", tid);
        formData.append("channelId", channelId);
        formData.append("realPremium", realPremium);
        formData.append("settlementDate", settlementDate);
        formData.append("capitalSourcr", capitalSourcr);
        formData.append("remark", remark);
        $.ajax({
            url: "/receivable/orderSettlement",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                if (data.success == true) {
                    $('#modalSettlement').modal('hide');
                    window.location.href = "/receivable/tolist?initFlag=2";
                } else {
                    Ewin.alert(data.msg);
                    return;
                }
            },
            error: function () {
                Ewin.alert(data.msg);
            }
        });
    }
}

//应收订单退保初始化
function surrender(capitalId, ordId) {
    var formData = new FormData();
    formData.append("capitalId", capitalId);
    formData.append("ordId", ordId);
    $.ajax({
        url: "/receivable/checkSurrenderData",
        type: "POST",
        data: formData,
        //必须false才会自动加上正确的Content-Type
        contentType: false,
        //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
        processData: false,
        success: function (data) {
            if (data.success == true) {
                var channelFlag = data.result.channelFlag;
                var channelStatus = data.result.channelStatus;
                var insureStartDate = data.result.insureStartDate;
                if (channelStatus == 4) {
                    Ewin.alert('请先完成该渠道应收保费的结算审核');
                    return false;
                } else {
                    $('#surrenderForm').parsley().reset();
                    $('#inputPayInsurerAmt').val('');
                    $('#inputMustPremiumAmt').val('');
                    if (channelFlag == 1) {
                        $('#inputMustPremium').val('');
                        $('#inputMustPremium').attr('data-parsley-required', true);
                        $('#inputMustPremium').attr('data-parsley-required-message', "请输入退保应扣除渠道佣金");
                        $('#mustPremium').removeClass('hidden');
                    } else {
                        $('#mustPremium').addClass('hidden');
                        $('#inputMustPremium').val('');
                    }
                    $('#surrenderTid').val(capitalId);
                    $('#orderTid').val(ordId);
                    $('#channelFlag').val(channelFlag);
                    $('#inputInsuranceDate').val(insureStartDate);
                    $('#inputSurrenderDate').val(new Date().Format("yyyy-MM-dd"));
                    $('#surrenderRemark').val("");
                    $('#modalSurrender').modal({backdrop: 'static', keyboard: false});
                }
            } else {
                Ewin.alert(data.msg);
                return;
            }
        },
        error: function () {
            Ewin.alert(data.msg);
        }
    });
}
//应收订单退保确定
function orderSurrender() {
    var surrenderForm = $('#surrenderForm').submit().parsley();
    console.log(surrenderForm.isValid());
    if(surrenderForm.isValid()) {
        var formData = new FormData();
        formData.append("ordId", $('#orderTid').val());
        formData.append("tid", $('#surrenderTid').val());
        formData.append("surrenderDateStr", $('#inputSurrenderDate').val());
        formData.append("mustPremiumAmt", $('#inputMustPremiumAmt').val());
        formData.append("payInsurerAmt", $('#inputPayInsurerAmt').val());
        formData.append("mustPremium", $('#inputMustPremium').val());
        formData.append("remark", $('#surrenderRemark').val());
        $.ajax({
            url: "/receivable/orderSurrender",
            type: "POST",
            data: formData,
            //必须false才会自动加上正确的Content-Type
            contentType: false,
            //必须false才会避开jQuery对 formdata 的默认处理,XMLHttpRequest会对 formdata 进行正确的处理
            processData: false,
            success: function (data) {
                if (data.success == true) {
                    $('#modalSurrender').modal('hide');
                    window.parent.location.reload();
                } else {
                    Ewin.alert(data.msg);
                    return;
                }
            },
            error: function () {
                Ewin.alert(data.msg);
            }
        });
    }
}

// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

function companyOrderSearch(){
    table.ajax.reload();
}

function toolBarInit(initType) {
    if (initType == 1) {
        // $("#toolBar li:eq(2)").addClass("hidden");
        // $("#toolBar li:eq(3)").addClass("hidden");
        // $("#toolBar li:eq(4)").removeClass("hidden");
        // $("#toolBar li:eq(5)").removeClass("hidden");
        // $("#toolBar li:eq(6)").removeClass("hidden");
        // $("#toolBar li:eq(7)").removeClass("hidden");

        $("#default3").addClass("hidden");
        $("#default4").addClass("hidden");
        $("#default5").removeClass("hidden");
        $("#default6").removeClass("hidden");
        $("#default7").removeClass("hidden");
        $("#default8").removeClass("hidden");
        $("#default9").addClass("hidden");
    } else if (initType == 2) {
        // $("#toolBar li:eq(2)").addClass("hidden");
        // $("#toolBar li:eq(3)").addClass("hidden");
        // $("#toolBar li:eq(4)").addClass("hidden");
        // $("#toolBar li:eq(5)").addClass("hidden");
        // $("#toolBar li:eq(6)").addClass("hidden");
        // $("#toolBar li:eq(7)").addClass("hidden");

        $("#default3").addClass("hidden");
        $("#default4").addClass("hidden");
        $("#default5").addClass("hidden");
        $("#default6").addClass("hidden");
        $("#default7").addClass("hidden");
        $("#default8").addClass("hidden");
        $("#default9").removeClass("hidden");
    }
}

//审核页面保单信息初始化
function initOrderInfo(orderInfo, companyRecord, channelRecord) {
    //保单号
    $('#orderNumShow').html(orderInfo.ordNum);
    //车主
    $('#carOwnerShow').html(orderInfo.carOwner);
    //车牌号
    $('#plateNumShow').html(orderInfo.plateNum);
    //车架号
    $('#frameNumberShow').html(orderInfo.frameNumber);
    //车辆种类
    if (orderInfo.vehicleType == 1) {
        $('#vehicleTypeShow').html("客车");
    } else {
        $('#vehicleTypeShow').html("货车");
    }
    //被保险人
    $('#insurantShow').html(orderInfo.insurant);
    //被保险人身份证号码/组织机构代码
    $('#orgIdCodeShow').html(orderInfo.orgIdCode);
    //投保人
    if (orderInfo.applicant != null) {
        $('#applicantShow').html(orderInfo.applicant);
    }
    //保险公司
    $('#insyrerNameShow').html(orderInfo.insyrerName);
    //险种
    if (orderInfo.typeInsurance == 0) {
        $('#typeInsuranceShow').html("交强险");
    } else if (orderInfo.typeInsurance == 1) {
        $('#typeInsuranceShow').html("商业险");
    } else {
        $('#typeInsuranceShow').html("");
    }
    //保单生效日期
    if (orderInfo.insureStartDate != null) {
        $('#insureStartDateShow').html(orderInfo.insureStartDate);
    }
    //垫资类型
    if (orderInfo.typeInsurance2 == 1) {
        $('#typeInsurance2Show').html("无垫资");
    } else if (orderInfo.typeInsurance2 == 2) {
        $('#typeInsurance2Show').html("垫返点");
    } else if (orderInfo.typeInsurance2 == 3) {
        $('#typeInsurance2Show').html("垫保费");
    }
    //垫资账期
    $('#laonAccountShow').html(orderInfo.laonAccount);
    //保险费
    if (orderInfo.typeInsurance == 1) { //商业险
        $('#premiumDiv').remove();
        $('#vvTaxDiv').remove();
        $('#followDiv').remove();
        $('#replenishDiv').remove();
        $('#insInfoDiv').append("<div id='premiumDiv' class='form-group'><label class='control-label col-md-4 col-sm-0'>商业保险费：</label><div class='col-md-6 col-sm-6'><p class='form-control-static'>" + orderInfo.mercialPremium + "元</p></div></div>");
    } else if (orderInfo.typeInsurance == 0) { //交强险
        $('#premiumDiv').remove();
        $('#vvTaxDiv').remove();
        $('#followDiv').remove();
        $('#replenishDiv').remove();
        $('#insInfoDiv').append("<div id='premiumDiv' class='form-group'><label class='control-label col-md-4 col-sm-0'>交强保险费：</label><div class='col-md-6 col-sm-6'><p class='form-control-static'>" + orderInfo.pulsoryPremium + "元</p></div></div>");
        $('#insInfoDiv').append("<div id='vvTaxDiv' class='form-group'><label class='control-label col-md-4 col-sm-0'>车船税：</label><div class='col-md-6 col-sm-6'><p class='form-control-static'>" + orderInfo.vechcleVesselTax + "元</p></div></div>");
    }
    //保险公司返点
    if (orderInfo.typeInsurance == 1) { //商业险
        $('#followDiv').remove();
        $('#replenishDiv').remove();
        $('#insInfoDiv').append("<div id='followDiv' class='form-group'><label class='control-label col-md-4 col-sm-0'>商业险跟单点位：</label><div class='col-md-6 col-sm-6'><p class='form-control-static'>" + orderInfo.followPoint + "%</p></div></div>");
        $('#insInfoDiv').append("<div id='replenishDiv' class='form-group'><label class='control-label col-md-4 col-sm-0'>商业险补点点位：</label><div class='col-md-6 col-sm-6'><p class='form-control-static'>" + orderInfo.replenishPoint + "%</p></div></div>");
    } else if (orderInfo.typeInsurance == 0) { //交强险
        $('#followDiv').remove();
        $('#replenishDiv').remove();
        $('#insInfoDiv').append("<div id='followDiv' class='form-group'><label class='control-label col-md-4 col-sm-0'>交强险跟单点位：</label><div class='col-md-6 col-sm-6'><p class='form-control-static'>" + orderInfo.followPoint + "%</p></div></div>");
        $('#insInfoDiv').append("<div id='replenishDiv' class='form-group'><label class='control-label col-md-4 col-sm-0'>交强险补点点位：</label><div class='col-md-6 col-sm-6'><p class='form-control-static'>" + orderInfo.replenishPoint + "%</p></div></div>");
    }
    //全保费
    $('#allPremiumShow').html(orderInfo.allPremium + "元");
    //渠道应支付保费合计
    if (channelRecord != null) {
        $('#mustPremiumShow').html(channelRecord.mustPremium + "元");
    }
    $('#allPremiumShow').html(orderInfo.allPremium + "元");
    //保险公司跟单手续费
    $('#followRpoundageShow').html(companyRecord.followRpoundage + "元");
    //保险公司补点手续费
    $('#replenishRpoundageShow').html(companyRecord.replenishRpoundage + "元");
    //税后保费
    $('#texPremiumShow').html(orderInfo.texPremium + "元");
    //渠道返点
    $('#channelPointShow').html(orderInfo.channelRebate + "%");
    //渠道返佣费合计
    if (companyRecord.realPremiumAmt != '' && companyRecord.realPremiumAmt != null) {
        $('#channelRebateShow').html(companyRecord.realPremiumAmt + "元");
    }
    //付款主体
    if (orderInfo.paySubject == 1) {
        $('#paySubjectShow').html("环宇康泰");
    } else if (orderInfo.paySubject == 2) {
        $('#paySubjectShow').html("青岛盛达");
    } else if (orderInfo.paySubject == 3) {
        $('#paySubjectShow').html("玉环天云");
    } else if (orderInfo.paySubject == 4) {
        $('#paySubjectShow').html("汉龙");
    }
    //出单员
    $('#followUserShow').html(orderInfo.saleman);
    //出单日期
    $('#dateIssuanceShow').html(orderInfo.dateIssuance);

}

//审核页面应付信息初始化
function initPayInfo (companyRecord, channelRecord) {
    if (channelRecord != null) {
        //收渠道金额
        $('#realPremiumShow').html(channelRecord.realPremium + "元");
        //收款日期
        $('#receiptDateShow').html(channelRecord.receiptDate);
        //应付返佣费
        $('#mustRebateAmtShow').html(channelRecord.mustPremiumAmt + "元");
        //付返佣费
        if (channelRecord.realPremiumAmt != '' && channelRecord.realPremiumAmt != null) {
            $('#realRebateAmtShow').html(channelRecord.realPremiumAmt + "元");
        }
        //付返佣费日期
        $('#channelPayDateShow').html(channelRecord.payDate);
    }
    //付保险公司金额
    if (companyRecord.payInsurerAmt != '' && companyRecord.payInsurerAmt != null) {
        $('#payInsurerAmtShow').html(companyRecord.payInsurerAmt + "元");
    }
    //付保险公司日期
    $('#payDateShow').html(companyRecord.payDate);

}

//审核页面应收信息初始化
function initReceivableInfo (orderInfo, companyRecord, channelRecord) {
    //跟单点位
    $('#rFollowPointShow').html(orderInfo.followPoint + "%");
    //补点点位
    $('#rReplenishPointShow').html(orderInfo.replenishPoint + "%");
    //跟单手续费
    $('#rFollowRpoundageShow').html(companyRecord.followRpoundage + "元");
    //补点手续费
    $('#rReplenishRpoundageShow').html(companyRecord.replenishRpoundage + "元");
    //核对结果
    if (companyRecord.checkResult == 1) {
        $('#rCheckResultShow').html("核对一致");
    } else if (companyRecord.checkResult == 2) {
        $('#rCheckResultShow').html("核对不一致");
    }
    //核对税后保费
    if (companyRecord.checkPremium != null && companyRecord.checkPremium != '') {
        $('#rCheckPremiumShow').html(companyRecord.checkPremium + "元");
    }
    //核对跟单点位
    if (companyRecord.checkFollowPoint != null && companyRecord.checkFollowPoint != '') {
        $('#rChechFollowRpoundageShow').html(companyRecord.checkFollowPoint + "%");
    }
    //核对补点点位
    if (companyRecord.checkReplenishPoint != null && companyRecord.checkReplenishPoint != '') {
        $('#rCheckReplenishRpoundageShow').html(companyRecord.checkReplenishPoint + "%");
    }
    //核对时间
    if (companyRecord.checkDate != null && companyRecord.checkDate != '') {
        $('#rCheckDateShow').html(companyRecord.checkDate);
    }
    //是否开票
    if (companyRecord.isTicketOpen == 0) {
        $('#rIsTicketOpenShow').html("未开票");
    } else if (companyRecord.isTicketOpen == 1) {
        $('#rIsTicketOpenShow').html("已开票");
    }
    //开票时间
    $('#rTicketOpenTimeShow').html(companyRecord.ticketOpenTime);
    //实收保险公司手续费
    if (companyRecord.realPremiumAmt != null && companyRecord.realPremiumAmt != '') {
        $('#rRealRebateAmtShow').html(companyRecord.realPremiumAmt + "元");
    }
    //实收跟单手续费
    if (companyRecord.realFollowRpoundage != null && companyRecord.realFollowRpoundage != '') {
        $('#realFollowRpoundageShow').html(companyRecord.realFollowRpoundage + "元");
    }
    //实收补点手续费
    if (companyRecord.realReplenishRpoundage != null && companyRecord.realReplenishRpoundage != '') {
        $('#realReplenishRpoundageShow').html(companyRecord.realReplenishRpoundage + "元");
    }
    //收款时间
    $('#rReceiptDateShow').html(companyRecord.receiptDate);
    //账期到期日
    $('#rInsyrerMaturityDateShow').html(orderInfo.insyrerMaturityDate);
    if (channelRecord != null) {
        //应收渠道保费
        $('#rMustPremiumShow').html(channelRecord.mustPremium + "元");
        //实收渠道保费
        $('#rRealPremiumShow').html(channelRecord.realPremium + "元");
        //收取日期
        $('#rChannelReceiptDateShow').html(channelRecord.receiptDate);
        //渠道收费来源
        if (channelRecord.capitalSourcr == 1) {
            $('#rCapitalSourcrShow').html("渠道支付");
        } else if (channelRecord.capitalSourcr == 2) {
            $('#rCapitalSourcrShow').html("保证金");
        }
    }

}

//审核页面订单操作记录初始化
function initBusinessLog(optionList) {
    var html = "";
    var remark = "";
    jQuery.each(optionList, function(i, val) {
        if (val.remark != null && val.remark != '') {
            remark = val.remark;
        }
        html += "<tr><td style='text-align: left;'>" + val.content + "</td><td>" + val.createUser.realName + "</td><td>" + val.createAt + "</td><td>" + remark + "</td></tr>";
    });
    $('#logTable').append(html);
}

//导入收款弹出框
function showGatheringModal() {
    $('#batchGatheringForm').parsley().reset();
    $('#batchGatheringDate').val(new Date().Format("yyyy-MM-dd"));
    $('#importGatheringFile').val("");
    $('#modalBatchGathering').modal({backdrop: 'static', keyboard: false});
}

//导入开票弹出框
function showInvoiceModal() {
    $('#importInvoiceFile').val("");
    $('#modalBatchInvoice').modal({backdrop: 'static', keyboard: false});
}

//导入核对弹出框
function showCheckModal() {
    $('#importCheckFile').val("");
    $('#modalBatchCheck').modal({backdrop: 'static', keyboard: false});
}